import { mountElement } from "./mountElement"
import { updateComponent } from "./updateComponent"

/* 
模块功能：比对组件差异，并更新
  1. 同一组件
  2. 不同组件

*/
function isSameComponent (vdom, oldComponent) {
  // 构造函数相同即相等
  return oldComponent && vdom.type === oldComponent.constructor
}

export function diffComponent (vdom, oldComponent, oldDom, container) {
  if (isSameComponent(vdom, oldComponent)) {
    updateComponent(vdom, oldComponent, oldDom, container)
  } else {
    mountElement(vdom, container, oldDom)
  }
}
